home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources-Targets / i960.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-05  |  54.2 KB  |  2,246 lines  |  [TEXT/MPS ]

  1. /* Subroutines used for code generation on intel 80960.
  2.    Copyright (C) 1992 Free Software Foundation, Inc.
  3.    Contributed by Steven McGeady, Intel Corp.
  4.    Additional Work by Glenn Colon-Bonet, Jonathan Shapiro, Andy Wilson
  5.    Converted to GCC 2.0 by Jim Wilson and Michael Tiemann, Cygnus Support.
  6.  
  7. This file is part of GNU CC.
  8.  
  9. GNU CC is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2, or (at your option)
  12. any later version.
  13.  
  14. GNU CC is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with GNU CC; see the file COPYING.  If not, write to
  21. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  22.  
  23. #include <stdio.h>
  24.  
  25. #include "config.h"
  26. #include "rtl.h"
  27. #include "regs.h"
  28. #include "hard-reg-set.h"
  29. #include "real.h"
  30. #include "insn-config.h"
  31. #include "conditions.h"
  32. #include "insn-flags.h"
  33. #include "output.h"
  34. #include "insn-attr.h"
  35. #include "flags.h"
  36. #include "tree.h"
  37. #include "insn-codes.h"
  38. #include "assert.h"
  39. #include "expr.h"
  40. #include "function.h"
  41. #include "recog.h"
  42. #include <math.h>
  43.  
  44. /* Save the operands last given to a compare for use when we
  45.    generate a scc or bcc insn.  */
  46.  
  47. rtx i960_compare_op0, i960_compare_op1;
  48.  
  49. /* Used to implement #pragma align/noalign.  Initialized by OVERRIDE_OPTIONS
  50.    macro in i960.h.  */
  51.  
  52. static int i960_maxbitalignment;
  53. static int i960_last_maxbitalignment;
  54.  
  55. /* Used to implement switching between MEM and ALU insn types, for better
  56.    C series performance.  */
  57.  
  58. enum insn_types i960_last_insn_type;
  59.  
  60. /* The leaf-procedure return register.  Set only if this is a leaf routine.  */
  61.  
  62. static int i960_leaf_ret_reg;
  63.  
  64. /* True if replacing tail calls with jumps is OK.  */
  65.  
  66. static int tail_call_ok;
  67.  
  68. /* A string containing a list of insns to emit in the epilogue so as to
  69.    restore all registers saved by the prologue.  Created by the prologue
  70.    code as it saves registers away.  */
  71.  
  72. char epilogue_string[1000];
  73.  
  74. /* A unique number (per function) for return labels.  */
  75.  
  76. static int ret_label = 0;
  77.  
  78. #if 0
  79. /* Handle pragmas for compatibility with Intel's compilers.  */
  80.  
  81. /* ??? This is incomplete, since it does not handle all pragmas that the
  82.    intel compilers understand.  Also, it needs to be rewritten to accept
  83.    a stream instead of a string for GCC 2.  */
  84.  
  85. void
  86. process_pragma(str)
  87.      char  *str;
  88. {
  89.   int align;
  90.   int i;
  91.  
  92.   if ((i = sscanf (str, " align %d", &align)) == 1)
  93.     switch (align)
  94.       {
  95.       case 0:            /* Return to last alignment.  */
  96.         align = i960_last_maxbitalignment / 8;
  97.  
  98.       case 16:            /* Byte alignments. */
  99.       case 8:
  100.       case 4:
  101.       case 2:
  102.       case 1:
  103.         i960_last_maxbitalignment = i960_maxbitalignment;
  104.         i960_maxbitalignment = align * 8;
  105.         break;
  106.  
  107.       default:            /* Unknown, silently ignore.  */
  108.         break;
  109.       }
  110.  
  111.   /* NOTE: ic960 R3.0 pragma align definition:
  112.  
  113.      #pragma align [(size)] | (identifier=size[,...])
  114.      #pragma noalign [(identifier)[,...]]
  115.  
  116.      (all parens are optional)
  117.  
  118.      - size is [1,2,4,8,16]
  119.      - noalign means size==1
  120.      - applies only to component elements of a struct (and union?)
  121.      - identifier applies to structure tag (only)
  122.      - missing identifier means next struct
  123.  
  124.      - alignment rules for bitfields need more investigation  */
  125.  
  126.   /* Should be pragma 'far' or equivalent for callx/balx here.  */
  127. }
  128. #endif
  129.  
  130. /* Initialize variables before compiling any files.  */
  131.  
  132. void
  133. i960_initialize ()
  134. {
  135.   if (TARGET_IC_COMPAT2_0)
  136.     {
  137.       i960_maxbitalignment = 8;
  138.       i960_last_maxbitalignment = 128;
  139.     }
  140.   else
  141.     {
  142.       i960_maxbitalignment = 128;
  143.       i960_last_maxbitalignment = 8;
  144.     }
  145. }
  146.  
  147. /* Return true if OP can be used as the source of an fp move insn.  */
  148.  
  149. int
  150. fpmove_src_operand (op, mode)
  151.      rtx op;
  152.      enum machine_mode mode;
  153. {
  154.   return (GET_CODE (op) == CONST_DOUBLE || general_operand (op, mode));
  155. }
  156.  
  157. #if 0
  158. /* Return true if OP is a register or zero.  */
  159.  
  160. int
  161. reg_or_zero_operand (op, mode)
  162.      rtx op;
  163.      enum machine_mode mode;
  164. {
  165.   return register_operand (op, mode) || op == const0_rtx;
  166. }
  167. #endif
  168.  
  169. /* Return truth value of whether OP can be used as an operands in a three
  170.    address arithmetic insn (such as add %o1,7,%l2) of mode MODE.  */
  171.  
  172. int
  173. arith_operand (op, mode)
  174.      rtx op;
  175.      enum machine_mode mode;
  176. {
  177.   return (register_operand (op, mode) || literal (op, mode));
  178. }
  179.  
  180. /* Return true if OP is a register or a valid floating point literal.  */
  181.  
  182. int
  183. fp_arith_operand (op, mode)
  184.      rtx op;
  185.      enum machine_mode mode;
  186. {
  187.   return (register_operand (op, mode) || fp_literal (op, mode));
  188. }
  189.  
  190. /* Return true is OP is a register or a valid signed integer literal.  */
  191.  
  192. int
  193. signed_arith_operand (op, mode)
  194.      rtx op;
  195.      enum machine_mode mode;
  196. {
  197.   return (register_operand (op, mode) || signed_literal (op, mode));
  198. }
  199.  
  200. /* Return truth value of whether OP is a integer which fits the
  201.    range constraining immediate operands in three-address insns.  */
  202.  
  203. int
  204. literal (op, mode)
  205.      rtx op;
  206.      enum machine_mode mode;
  207. {
  208.   return ((GET_CODE (op) == CONST_INT) && INTVAL(op) >= 0 && INTVAL(op) < 32);
  209. }
  210.  
  211. /* Return true if OP is a float constant of 1.  */
  212.  
  213. int
  214. fp_literal_one (op, mode)
  215.      rtx op;
  216.      enum machine_mode mode;
  217. {
  218.   return (TARGET_NUMERICS && (mode == VOIDmode || mode == GET_MODE (op))
  219.       && (op == CONST1_RTX (mode)));
  220. }
  221.  
  222. /* Return true if OP is a float constant of 0.  */
  223.  
  224. int
  225. fp_literal_zero (op, mode)
  226.      rtx op;
  227.      enum machine_mode mode;
  228. {
  229.   return (TARGET_NUMERICS && (mode == VOIDmode || mode == GET_MODE (op))
  230.       && (op == CONST0_RTX (mode)));
  231. }
  232.  
  233. /* Return true if OP is a valid floating point literal.  */
  234.  
  235. int
  236. fp_literal(op, mode)
  237.      rtx op;
  238.      enum machine_mode mode;
  239. {
  240.   return fp_literal_zero (op, mode) || fp_literal_one (op, mode);
  241. }
  242.  
  243. /* Return true if OP is a valid signed immediate constant.  */
  244.  
  245. int
  246. signed_literal(op, mode)
  247.      rtx op;
  248.      enum machine_mode mode;
  249. {
  250.   return ((GET_CODE (op) == CONST_INT) && INTVAL(op) > -32 && INTVAL(op) < 32);
  251. }
  252.  
  253. /* Return truth value of statement that OP is a symbolic memory
  254.    operand of mode MODE.  */
  255.  
  256. int
  257. symbolic_memory_operand (op, mode)
  258.      rtx op;
  259.      enum machine_mode mode;
  260. {
  261.   if (GET_CODE (op) == SUBREG)
  262.     op = SUBREG_REG (op);
  263.   if (GET_CODE (op) != MEM)
  264.     return 0;
  265.   op = XEXP (op, 0);
  266.   return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST
  267.       || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF);
  268. }
  269.  
  270. /* Return truth value of whether OP is EQ or NE.  */
  271.  
  272. int
  273. eq_or_neq (op, mode)
  274.      rtx op;
  275.      enum machine_mode mode;
  276. {
  277.   return (GET_CODE (op) == EQ || GET_CODE (op) == NE);
  278. }
  279.  
  280. /* OP is an integer register or a constant.  */
  281.  
  282. int
  283. arith32_operand (op, mode)
  284.      rtx op;
  285.      enum machine_mode mode;
  286. {
  287.   if (register_operand (op, mode))
  288.     return 1;
  289.   return (CONSTANT_P (op));
  290. }
  291.  
  292. /* Return true if OP is an integer constant which is a power of 2.  */
  293.  
  294. int
  295. power2_operand (op,mode)
  296.      rtx op;
  297.      enum machine_mode mode;
  298. {
  299.   if (GET_CODE(op) != CONST_INT)
  300.     return 0;
  301.  
  302.   return exact_log2 (INTVAL (op)) >= 0;
  303. }
  304.  
  305. /* If VAL has only one bit set, return the index of that bit.  Otherwise
  306.    return -1.  */
  307.  
  308. int
  309. bitpos (val)
  310.      unsigned int val;
  311. {
  312.   register int i;
  313.  
  314.   for (i = 0; val != 0; i++, val >>= 1)
  315.     {
  316.       if (val & 1)
  317.     {
  318.       if (val != 1)
  319.         return -1;
  320.       return i;
  321.     }
  322.     }
  323.   return -1;
  324. }
  325.  
  326. /* Return non-zero if OP is a mask, i.e. all one bits are consecutive.
  327.    The return value indicates how many consecutive non-zero bits exist
  328.    if this is a mask.  This is the same as the next function, except that
  329.    it does not indicate what the start and stop bit positions are.  */
  330.  
  331. int
  332. is_mask (val)
  333.      unsigned int val;
  334. {
  335.   register int start, end, i;
  336.  
  337.   start = -1;
  338.   for (i = 0; val != 0; val >>= 1, i++)
  339.     {
  340.       if (val & 1)
  341.     {
  342.       if (start < 0)
  343.         start = i;
  344.  
  345.       end = i;
  346.       continue;
  347.     }
  348.       /* Still looking for the first bit.  */
  349.       if (start < 0)
  350.     continue;
  351.  
  352.       /* We've seen the start of a bit sequence, and now a zero.  There
  353.      must be more one bits, otherwise we would have exited the loop.
  354.      Therefore, it is not a mask.  */
  355.       if (val)
  356.     return 0;
  357.     }
  358.  
  359.   /* The bit string has ones from START to END bit positions only.  */
  360.   return end - start + 1;
  361. }
  362.  
  363. /* If VAL is a mask, then return nonzero, with S set to the starting bit
  364.    position and E set to the ending bit position of the mask.  The return
  365.    value indicates how many consecutive bits exist in the mask.  This is
  366.    the same as the previous function, except that it also indicates the
  367.    start and end bit positions of the mask.  */
  368.  
  369. int
  370. bitstr (val, s, e)
  371.      unsigned int val;
  372.      int *s, *e;
  373. {
  374.   register int start, end, i;
  375.  
  376.   start = -1;
  377.   end = -1;
  378.   for (i = 0; val != 0; val >>= 1, i++)
  379.     {
  380.       if (val & 1)
  381.     {
  382.       if (start < 0)
  383.         start = i;
  384.  
  385.       end = i;
  386.       continue;
  387.     }
  388.  
  389.       /* Still looking for the first bit.  */
  390.       if (start < 0)
  391.     continue;
  392.  
  393.       /* We've seen the start of a bit sequence, and now a zero.  There
  394.      must be more one bits, otherwise we would have exited the loop.
  395.      Therefor, it is not a mask.  */
  396.       if (val)
  397.     {
  398.       start = -1;
  399.       end = -1;
  400.       break;
  401.     }
  402.     }
  403.  
  404.   /* The bit string has ones from START to END bit positions only.  */
  405.   *s = start;
  406.   *e = end;
  407.   return ((start < 0) ? 0 : end - start + 1);
  408. }
  409.  
  410. /* Return the machine mode to use for a comparison.  */
  411.  
  412. enum machine_mode
  413. select_cc_mode (op, x)
  414.      RTX_CODE op;
  415.      rtx x;
  416. {
  417.   if (op == GTU || op == LTU || op == GEU || op == LEU)
  418.     return CC_UNSmode;
  419.   return CCmode;
  420. }
  421.  
  422. /* X and Y are two things to compare using CODE.  Emit the compare insn and
  423.    return the rtx for register 36 in the proper mode.  */
  424.  
  425. rtx
  426. gen_compare_reg (code, x, y)
  427.      enum rtx_code code;
  428.      rtx x, y;
  429. {
  430.   rtx cc_reg;
  431.   enum machine_mode ccmode = SELECT_CC_MODE (code, x, y);
  432.   enum machine_mode mode
  433.     = GET_MODE (x) == VOIDmode ? GET_MODE (y) : GET_MODE (x);
  434.  
  435.   if (mode == SImode)
  436.     {
  437.       if (! arith_operand (x, mode))
  438.     x = force_reg (SImode, x);
  439.       if (! arith_operand (y, mode))
  440.     y = force_reg (SImode, y);
  441.     }
  442.  
  443.   cc_reg = gen_rtx (REG, ccmode, 36);
  444.   emit_insn (gen_rtx (SET, VOIDmode, cc_reg,
  445.               gen_rtx (COMPARE, ccmode, x, y)));
  446.  
  447.   return cc_reg;
  448. }
  449.  
  450. /* For the i960, REG is cost 1, REG+immed CONST is cost 2, REG+REG is cost 2,
  451.    REG+nonimmed CONST is cost 4.  REG+SYMBOL_REF, SYMBOL_REF, and similar
  452.    are 4.  Indexed addresses are cost 6.  */
  453.  
  454. /* ??? Try using just RTX_COST, i.e. not defining ADDRESS_COST.  */
  455.  
  456. int
  457. i960_address_cost (x)
  458.      rtx x;
  459. {
  460. #if 0
  461.   /* Handled before calling here.  */
  462.   if (GET_CODE (x) == REG)
  463.     return 1;
  464. #endif
  465.   if (GET_CODE (x) == PLUS)
  466.     {
  467.       rtx base = XEXP (x, 0);
  468.       rtx offset = XEXP (x, 1);
  469.  
  470.       if (GET_CODE (base) == SUBREG)
  471.     base = SUBREG_REG (base);
  472.       if (GET_CODE (offset) == SUBREG)
  473.     offset = SUBREG_REG (offset);
  474.  
  475.       if (GET_CODE (base) == REG)
  476.     {
  477.       if (GET_CODE (offset) == REG)
  478.         return 2;
  479.       if (GET_CODE (offset) == CONST_INT)
  480.         {
  481.           if ((unsigned)INTVAL (offset) < 2047)
  482.         return 2;
  483.           return 4;
  484.         }
  485.       if (CONSTANT_P (offset))
  486.         return 4;
  487.     }
  488.       if (GET_CODE (base) == PLUS || GET_CODE (base) == MULT)
  489.     return 6;
  490.  
  491.       /* This is an invalid address.  The return value doesn't matter, but
  492.      for convenience we make this more expensive than anything else.  */
  493.       return 12;
  494.     }
  495.   if (GET_CODE (x) == MULT)
  496.     return 6;
  497.  
  498.   /* Symbol_refs and other unrecognized addresses are cost 4.  */
  499.   return 4;
  500. }
  501.  
  502. /* Emit insns to move operands[1] into operands[0].
  503.  
  504.    Return 1 if we have written out everything that needs to be done to
  505.    do the move.  Otherwise, return 0 and the caller will emit the move
  506.    normally.  */
  507.  
  508. int
  509. emit_move_sequence (operands, mode)
  510.      rtx *operands;
  511.      enum machine_mode mode;
  512. {
  513.   register rtx operand0 = operands[0];
  514.   register rtx operand1 = operands[1];
  515.  
  516.   /* We can only store registers to memory.  */
  517.  
  518.   if (GET_CODE (operand0) == MEM && GET_CODE (operand1) != REG)
  519.     operands[1] = force_reg (mode, operand1);
  520.  
  521.   return 0;
  522. }
  523.  
  524. /* Emit insns to load a constant.  Uses several strategies to try to use
  525.    as few insns as possible.  */
  526.  
  527. char *
  528. i960_output_ldconst (dst, src)
  529.      register rtx dst, src;
  530. {
  531.   register int rsrc1;
  532.   register unsigned rsrc2;
  533.   enum machine_mode mode = GET_MODE (dst);
  534.   rtx operands[4];
  535.   union { long l[2]; double d; } x;
  536.  
  537.   operands[0] = operands[2] = dst;
  538.   operands[1] = operands[3] = src;
  539.  
  540.   /* Anything that isn't a compile time constant, such as a SYMBOL_REF,
  541.      must be a ldconst insn.  */
  542.  
  543.   if (GET_CODE (src) != CONST_INT && GET_CODE (src) != CONST_DOUBLE)
  544.     {
  545.       output_asm_insn ("ldconst    %1,%0", operands);
  546.       return "";
  547.     }
  548.   else if (mode == DFmode)
  549.     {
  550.       rtx first, second;
  551.  
  552.       if (fp_literal_zero (src, VOIDmode))
  553.     {
  554.       if (FP_REG_P (dst))
  555.         return "movrl    %1,%0";
  556.       else
  557.         return "movl    0,%0";
  558.     }
  559.  
  560. #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
  561.       split_double (src, &first, &second);
  562.  
  563.       output_asm_insn ("# ldconst    %1,%0",operands);
  564.  
  565.       operands[0] = gen_rtx (REG, SImode, REGNO (dst));
  566.       operands[1] = first;
  567.       output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
  568.               operands);
  569.       operands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
  570.       operands[1] = second;
  571.       output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
  572.               operands);
  573.       return "";
  574. #else
  575.       if (fp_literal_one (src, VOIDmode))
  576.     return "movrl    0f1.0,%0";
  577.       fatal ("inline double constants not supported on this host");
  578. #endif
  579.     }
  580.   else if (mode == TImode)
  581.     {
  582.       /* ??? This is currently not handled at all.  */
  583.       abort ();
  584.  
  585.       /* Note: lowest order word goes in lowest numbered reg.  */
  586.       rsrc1 = INTVAL (src);
  587.       if (rsrc1 >= 0 && rsrc1 < 32)
  588.     return "movq    %1,%0";
  589.       else
  590.     output_asm_insn ("movq\t0,%0\t# ldconstq %1,%0",operands);
  591.       /* Go pick up the low-order word.  */
  592.     }
  593.   else if (mode == DImode)
  594.     {
  595.       rtx upperhalf, lowerhalf, xoperands[2];
  596.       char *string;
  597.  
  598.       if (GET_CODE (src) == CONST_DOUBLE)
  599.     {
  600.       upperhalf = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_HIGH (src));
  601.       lowerhalf = gen_rtx (CONST_INT, VOIDmode, CONST_DOUBLE_LOW (src));
  602.     }
  603.       else if (GET_CODE (src) == CONST_INT)
  604.     {
  605.       lowerhalf = src;
  606.       upperhalf = INTVAL (src) < 0 ? constm1_rtx : const0_rtx;
  607.     }
  608.       else
  609.     abort ();
  610.  
  611.       /* Note: lowest order word goes in lowest numbered reg.  */
  612.       /* Numbers from 0 to 31 can be handled with a single insn.  */
  613.       rsrc1 = INTVAL (lowerhalf);
  614.       if (upperhalf == const0_rtx && rsrc1 >= 0 && rsrc1 < 32)
  615.     return "movl    %1,%0";
  616.  
  617.       /* Output the upper half with a recursive call.  */
  618.       xoperands[0] = gen_rtx (REG, SImode, REGNO (dst) + 1);
  619.       xoperands[1] = upperhalf;
  620.       output_asm_insn (i960_output_ldconst (xoperands[0], xoperands[1]),
  621.                xoperands);
  622.       /* The lower word is emitted as normally.  */
  623.     }
  624.   else if (mode == SFmode)
  625.     {
  626. #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
  627.       REAL_VALUE_TYPE d;
  628.       long value;
  629.  
  630.       REAL_VALUE_FROM_CONST_DOUBLE (d, src);
  631.       REAL_VALUE_TO_TARGET_SINGLE (d, value);
  632.  
  633.       output_asm_insn ("# ldconst    %1,%0",operands);
  634.       operands[0] = gen_rtx (REG, SImode, REGNO (dst));
  635.       operands[1] = gen_rtx (CONST_INT, VOIDmode, value);
  636.       output_asm_insn (i960_output_ldconst (operands[0], operands[1]),
  637.               operands);
  638. #else
  639.       if (fp_literal_zero (src, VOIDmode))
  640.     return "movr    0f0.0,%0";
  641.       if (fp_literal_one (src, VOIDmode))
  642.     return "movr    0f1.0,%0";
  643.       fatal ("inline float constants not supported on this host");
  644. #endif
  645.       return "";
  646.     }
  647.   else
  648.     {
  649.       rsrc1 = INTVAL (src);
  650.       if (mode == QImode)
  651.     {
  652.       if (rsrc1 > 0xff)
  653.         rsrc1 &= 0xff;
  654.     }
  655.       else if (mode == HImode)
  656.     {
  657.       if (rsrc1 > 0xffff)
  658.         rsrc1 &= 0xffff;
  659.     }
  660.     }
  661.  
  662.   if (rsrc1 >= 0)
  663.     {
  664.       /* ldconst    0..31,X        ->     mov    0..31,X  */
  665.       if (rsrc1 < 32)
  666.     {
  667.       if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
  668.         return "lda    %1,%0";
  669.       return "mov    %1,%0";
  670.     }
  671.  
  672.       /* ldconst    32..63,X    ->    add    31,nn,X  */
  673.       if (rsrc1 < 63)
  674.     {
  675.       if (i960_last_insn_type == I_TYPE_REG && TARGET_C_SERIES)
  676.         return "lda    %1,%0";
  677.       operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc1 - 31);
  678.       output_asm_insn ("addo\t31,%1,%0\t# ldconst %3,%0", operands);
  679.       return "";
  680.     }
  681.     }
  682.   else if (rsrc1 < 0)
  683.     {
  684.       /* ldconst    -1..-31        ->    sub    0,0..31,X  */
  685.       if (rsrc1 >= -31)
  686.     {
  687.       /* return 'sub -(%1),0,%0' */
  688.       operands[1] = gen_rtx (CONST_INT, VOIDmode, - rsrc1);
  689.       output_asm_insn ("subo\t%1,0,%0\t# ldconst %3,%0", operands);
  690.       return "";
  691.     }
  692.       
  693.       /* ldconst    -32        ->    not    31,X  */
  694.       if (rsrc1 == -32)
  695.     {
  696.       operands[1] = gen_rtx (CONST_INT, VOIDmode, ~rsrc1);
  697.       output_asm_insn ("not\t%1,%0    # ldconst %3,%0", operands);
  698.       return "";
  699.     }
  700.     }
  701.  
  702.   /* If const is a single bit.  */
  703.   if (bitpos (rsrc1) >= 0)
  704.     {
  705.       operands[1] = gen_rtx (CONST_INT, VOIDmode, bitpos (rsrc1));
  706.       output_asm_insn ("setbit\t%1,0,%0\t# ldconst %3,%0", operands);
  707.       return "";
  708.     }
  709.  
  710.   /* If const is a bit string of less than 6 bits (1..31 shifted).  */
  711.   if (is_mask (rsrc1))
  712.     {
  713.       int s, e;
  714.  
  715.       if (bitstr (rsrc1, &s, &e) < 6)
  716.     {
  717.       rsrc2 = ((unsigned int) rsrc1) >> s;
  718.       operands[1] = gen_rtx (CONST_INT, VOIDmode, rsrc2);
  719.       operands[2] = gen_rtx (CONST_INT, VOIDmode, s);
  720.       output_asm_insn ("shlo\t%2,%1,%0\t# ldconst %3,%0", operands);
  721.       return "";
  722.     }
  723.     }
  724.  
  725.   /* Unimplemented cases:
  726.      const is in range 0..31 but rotated around end of word:
  727.      ror    31,3,g0    -> ldconst 0xe0000003,g0
  728.    
  729.      and any 2 instruction cases that might be worthwhile  */
  730.   
  731.   output_asm_insn ("ldconst    %1,%0", operands);
  732.   return "";
  733. }
  734.  
  735. /* Determine if there is an opportunity for a bypass optimization.
  736.    Bypass succeeds on the 960K* if the destination of the previous
  737.    instruction is the second operand of the current instruction.
  738.    Bypass always succeeds on the C*.
  739.  
  740.    Return 1 if the pattern should interchange the operands.
  741.  
  742.    CMPBR_FLAG is true if this is for a compare-and-branch insn.
  743.    OP1 and OP2 are the two source operands of a 3 operand insn.  */
  744.  
  745. int
  746. i960_bypass (insn, op1, op2, cmpbr_flag)
  747.      register rtx insn, op1, op2;
  748.      int cmpbr_flag;
  749. {
  750.   register rtx prev_insn, prev_dest;
  751.  
  752.   if (TARGET_C_SERIES)
  753.     return 0;
  754.  
  755.   /* Can't do this if op1 isn't a register.  */
  756.   if (! REG_P (op1))
  757.     return 0;
  758.  
  759.   /* Can't do this for a compare-and-branch if both ops aren't regs.  */
  760.   if (cmpbr_flag && ! REG_P (op2))
  761.     return 0;
  762.  
  763.   prev_insn = prev_real_insn (insn);
  764.  
  765.   if (prev_insn && GET_CODE (prev_insn) == INSN
  766.       && GET_CODE (PATTERN (prev_insn)) == SET)
  767.     {
  768.       prev_dest = SET_DEST (PATTERN (prev_insn));
  769.       if ((GET_CODE (prev_dest) == REG && REGNO (prev_dest) == REGNO (op1))
  770.       || (GET_CODE (prev_dest) == SUBREG
  771.           && GET_CODE (SUBREG_REG (prev_dest)) == REG
  772.           && REGNO (SUBREG_REG (prev_dest)) == REGNO (op1)))
  773.     return 1;
  774.     }
  775.   return 0;
  776. }
  777.  
  778. /* Output the code which declares the function name.  This also handles
  779.    leaf routines, which have special requirements, and initializes some
  780.    global variables.  */
  781.  
  782. void
  783. i960_function_name_declare (file, name, fndecl)
  784.      FILE *file;
  785.      char *name;
  786.      tree fndecl;
  787. {
  788.   register int i, j;
  789.   int leaf_proc_ok;
  790.   rtx insn;
  791.  
  792.   /* Increment global return label.  */
  793.  
  794.   ret_label++;
  795.  
  796.   /* Compute whether tail calls and leaf routine optimizations can be performed
  797.      for this function.  */
  798.  
  799.   if (TARGET_TAILCALL)
  800.     tail_call_ok = 1;
  801.   else
  802.     tail_call_ok = 0;
  803.  
  804.   if (TARGET_LEAFPROC)
  805.     leaf_proc_ok = 1;
  806.   else
  807.     leaf_proc_ok = 0;
  808.  
  809.   /* Even if nobody uses extra parms, can't have leafroc or tail calls if
  810.      argblock, because argblock uses g14 implicitly.  */
  811.  
  812.   if (current_function_args_size != 0)
  813.     {
  814.       tail_call_ok = 0;
  815.       leaf_proc_ok = 0;
  816.     }
  817.       
  818.   /* See if caller passes in an address to return value. */
  819.  
  820.   if (aggregate_value_p (DECL_RESULT (fndecl)))
  821.     {
  822.       tail_call_ok = 0;
  823.       leaf_proc_ok = 0;
  824.     }
  825.  
  826.   /* Can not use tail calls or make this a leaf routine if there is a non
  827.      zero frame size.  */
  828.  
  829.   if (get_frame_size () != 0)
  830.     leaf_proc_ok = 0;
  831.  
  832.   /* I don't understand this condition, and do not think that it is correct.
  833.      Apparently this is just checking whether the frame pointer is used, and
  834.      we can't trust regs_ever_live[fp] since it is (almost?) always set.  */
  835.  
  836.   if (tail_call_ok)
  837.     for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  838.       if (GET_CODE (insn) == INSN
  839.       && reg_mentioned_p (frame_pointer_rtx, insn))
  840.     {
  841.       tail_call_ok = 0;
  842.       break;
  843.     }
  844.  
  845.   /* Check for CALL insns.  Can not be a leaf routine if there are any.  */
  846.  
  847.   if (leaf_proc_ok)
  848.     for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  849.       if (GET_CODE (insn) == CALL_INSN)
  850.     {
  851.       leaf_proc_ok = 0;
  852.       break;
  853.     }
  854.  
  855.   /* Can not be a leaf routine if any non-call clobbered registers are
  856.      used in this function.  */
  857.  
  858.   if (leaf_proc_ok)
  859.     for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
  860.       if (regs_ever_live[i]
  861.       && ((! call_used_regs[i]) || (i > 7 && i < 12)))
  862.     {
  863.       /* Global registers.  */
  864.       if (i < 16 && i > 7 && i != 13)
  865.         leaf_proc_ok = 0;
  866.       /* Local registers.  */
  867.       else if (i < 32)
  868.         leaf_proc_ok = 0;
  869.     }
  870.  
  871.   /* Now choose a leaf return register, if we can find one, and if it is
  872.      OK for this to be a leaf routine.  */
  873.  
  874.   i960_leaf_ret_reg = -1;
  875.  
  876.   if (optimize && leaf_proc_ok)
  877.     {
  878.       for (i960_leaf_ret_reg = -1, i = 0; i < 8; i++)
  879.     if (regs_ever_live[i] == 0)
  880.       {
  881.         i960_leaf_ret_reg = i;
  882.         regs_ever_live[i] = 1;
  883.         break;
  884.       }
  885.     }
  886.  
  887.   /* Do this after choosing the leaf return register, so it will be listed
  888.      if one was chosen.  */
  889.  
  890.   fprintf (file, "\t#  Function '%s'\n", name);
  891.   fprintf (file, "\t#  Registers used: ");
  892.  
  893.   for (i = 0, j = 0; i < FIRST_PSEUDO_REGISTER; i++)
  894.     {
  895.       if (regs_ever_live[i])
  896.     {
  897.       fprintf (file, "%s%s ", reg_names[i], call_used_regs[i] ? "" : "*");
  898.  
  899.       if (i > 15 && j == 0)
  900.         {
  901.           fprintf (file,"\n\t#\t\t   ");
  902.           j++;
  903.             }
  904.         }
  905.     }
  906.  
  907.   fprintf (file, "\n");
  908.  
  909.   if (i960_leaf_ret_reg >= 0)
  910.     {
  911.       /* Make it a leaf procedure.  */
  912.  
  913.       if (TREE_PUBLIC (fndecl))
  914.     fprintf (file,"\t.globl    %s.lf\n", name);
  915.  
  916.       fprintf (file, "\t.leafproc\t_%s,%s.lf\n", name, name);
  917.       fprintf (file, "_%s:\n", name);
  918.       fprintf (file, "\tlda    LR%d,g14\n", ret_label);
  919.       fprintf (file, "%s.lf:\n", name);
  920.       fprintf (file, "\tmov    g14,g%d\n", i960_leaf_ret_reg);
  921.  
  922.       if (TARGET_C_SERIES)
  923.     {
  924.       fprintf (file, "\tlda    0,g14\n");
  925.       i960_last_insn_type = I_TYPE_MEM;
  926.     }
  927.       else
  928.     {
  929.       fprintf (file, "\tmov    0,g14\n");
  930.       i960_last_insn_type = I_TYPE_REG;
  931.     }
  932.     }
  933.   else
  934.     {
  935.       ASM_OUTPUT_LABEL (file, name);
  936.       i960_last_insn_type = I_TYPE_CTRL; 
  937.     }
  938. }
  939.  
  940. /* Compute and return the frame size.  */
  941.  
  942. int
  943. compute_frame_size (size)
  944.      int size;
  945. {
  946.   int actual_fsize;
  947.   int outgoing_args_size
  948.     = current_function_outgoing_args_size + current_function_pretend_args_size;
  949.  
  950.   /* The STARTING_FRAME_OFFSET is totally hidden to us as far
  951.      as size is concerned.  */
  952.   actual_fsize = (size + 15) & -16;
  953.   actual_fsize += (outgoing_args_size + 15) & -16;
  954.  
  955.   return actual_fsize;
  956. }
  957.  
  958. /* Output code for the function prologue.  */
  959.  
  960. void
  961. i960_function_prologue (file, size)
  962.      FILE *file;
  963.      unsigned int size;
  964. {
  965.   register int i, j, nr;
  966.   int n_iregs = 0;
  967.   int rsize = 0;
  968.   int actual_fsize, offset;
  969.   char tmpstr[1000];
  970.   /* -1 if reg must be saved on proc entry, 0 if available, 1 if saved
  971.      somewhere.  */
  972.   int regs[FIRST_PSEUDO_REGISTER];
  973.  
  974.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  975.     if (regs_ever_live[i]
  976.     && ((! call_used_regs[i]) || (i > 7 && i < 12)))
  977.       {
  978.     regs[i] = -1;
  979.         /* Count global registers that need saving.  */
  980.     if (i < 16)
  981.       n_iregs++;
  982.       }
  983.     else
  984.       regs[i] = 0;
  985.  
  986.   epilogue_string[0] = '\0';
  987.  
  988.   /* First look for local registers to save globals in.  */
  989.   for (i = 0; i < 16; i++)
  990.     {
  991.       if (regs[i] == 0)
  992.     continue;
  993.  
  994.       /* Start at r4, not r3.  */
  995.       for (j = 20; j < 32; j++)
  996.     {
  997.       if (regs[j] != 0)
  998.         continue;
  999.  
  1000.       regs[i] = 1;
  1001.       regs[j] = -1;
  1002.       regs_ever_live[j] = 1;
  1003.       nr = 1;
  1004.       if (i <= 14 && i % 2 == 0 && j <= 30 && j % 2 == 0
  1005.           && regs[i+1] != 0 && regs[j+1] == 0)
  1006.         {
  1007.           nr = 2;
  1008.           regs[i+1] = 1;
  1009.           regs[j+1] = -1;
  1010.           regs_ever_live[j+1] = 1;
  1011.         }
  1012.       if (nr == 2 && i <= 12 && i % 4 == 0 && j <= 28 && j % 4 == 0
  1013.           && regs[i+2] != 0 && regs[j+2] == 0)
  1014.         {
  1015.           nr = 3;
  1016.           regs[i+2] = 1;
  1017.           regs[j+2] = -1;
  1018.           regs_ever_live[j+2] = 1;
  1019.         }
  1020.       if (nr == 3 && regs[i+3] != 0 && regs[j+3] == 0)
  1021.         {
  1022.           nr = 4;
  1023.           regs[i+3] = 1;
  1024.           regs[j+3] = -1;
  1025.           regs_ever_live[j+3] = 1;
  1026.         }
  1027.  
  1028.       fprintf (file, "\tmov%s    %s,%s\n",
  1029.            ((nr == 4) ? "q" :
  1030.             (nr == 3) ? "t" :
  1031.             (nr == 2) ? "l" : ""),
  1032.            reg_names[i], reg_names[j]);
  1033.       sprintf (tmpstr, "\tmov%s    %s,%s\n",
  1034.            ((nr == 4) ? "q" :
  1035.             (nr == 3) ? "t" :
  1036.             (nr == 2) ? "l" : ""),
  1037.            reg_names[j], reg_names[i]);
  1038.       strcat (epilogue_string, tmpstr);
  1039.  
  1040.       n_iregs -= nr;
  1041.       i += nr-1;
  1042.       break;
  1043.     }
  1044.     }
  1045.  
  1046.   /* N_iregs is now the number of global registers that haven't been saved
  1047.      yet.  */
  1048.  
  1049.   rsize = (n_iregs * 4);
  1050.   actual_fsize = compute_frame_size (size) + rsize;
  1051. #if 0
  1052.   /* ??? The 1.2.1 compiler does this also.  This is meant to round the frame
  1053.      size up to the nearest multiple of 16.  I don't know whether this is
  1054.      necessary, or even desirable.
  1055.  
  1056.      The frame pointer must be aligned, but the call instruction takes care of
  1057.      that.  If we leave the stack pointer unaligned, we may save a little on
  1058.      dynamic stack allocation.  And we don't lose, at least according to the
  1059.      i960CA manual.  */
  1060.   actual_fsize = (actual_fsize + 15) & ~0xF;
  1061. #endif
  1062.  
  1063.   /* Allocate space for register save and locals.  */
  1064.   if (actual_fsize > 0)
  1065.     {
  1066.       if (actual_fsize < 32)
  1067.     fprintf (file, "\taddo    %d,sp,sp\n", actual_fsize);
  1068.       else
  1069.     fprintf (file, "\tlda\t%d(sp),sp\n", actual_fsize);
  1070.     }
  1071.  
  1072.   /* Take hardware register save area created by the call instruction
  1073.      into account.  */
  1074.   offset = compute_frame_size (size) + 64;
  1075.   /* Save registers on stack if needed.  */
  1076.   for (i = 0, j = n_iregs; j > 0 && i < 16; i++)
  1077.     {
  1078.       if (regs[i] != -1)
  1079.     continue;
  1080.  
  1081.       nr = 1;
  1082.  
  1083.       if (i <= 14 && i % 2 == 0 && regs[i+1] == -1 && offset % 2 == 0)
  1084.     nr = 2;
  1085.  
  1086.       if (nr == 2 && i <= 12 && i % 4 == 0 && regs[i+2] == -1
  1087.       && offset % 4 == 0)
  1088.     nr = 3;
  1089.  
  1090.       if (nr == 3 && regs[i+3] == -1)
  1091.     nr = 4;
  1092.  
  1093.       fprintf (file,"\tst%s    %s,%d(fp)\n",
  1094.            ((nr == 4) ? "q" :
  1095.         (nr == 3) ? "t" :
  1096.         (nr == 2) ? "l" : ""),
  1097.            reg_names[i], offset);
  1098.       sprintf (tmpstr,"\tld%s    %d(fp),%s\n",
  1099.            ((nr == 4) ? "q" :
  1100.         (nr == 3) ? "t" :
  1101.         (nr == 2) ? "l" : ""),
  1102.            offset, reg_names[i]);
  1103.       strcat (epilogue_string, tmpstr);
  1104.       i += nr-1;
  1105.       j -= nr;
  1106.       offset += nr * 4;
  1107.     }
  1108.  
  1109.   if (actual_fsize == 0 && size == 0 && rsize == 0)
  1110.     return;
  1111.  
  1112.   fprintf (file, "\t#Prologue stats:\n");
  1113.   fprintf (file, "\t#  Total Frame Size: %d bytes\n", actual_fsize);
  1114.  
  1115.   if (size)
  1116.     fprintf (file, "\t#  Local Variable Size: %d bytes\n", size);
  1117.   if (rsize)
  1118.     fprintf (file, "\t#  Register Save Size: %d regs, %d bytes\n",
  1119.          n_iregs, rsize);
  1120.   fprintf (file, "\t#End Prologue#\n");
  1121. }
  1122.  
  1123. /* Output code for the function epilogue.  */
  1124.  
  1125. void
  1126. i960_function_epilogue (file, size)
  1127.      FILE *file;
  1128.      unsigned int size;
  1129. {
  1130.   if (i960_leaf_ret_reg >= 0)
  1131.     {
  1132.       fprintf (file, "LR%d:    ret\n", ret_label);
  1133.       return;
  1134.     }
  1135.  
  1136.   if (*epilogue_string == 0)
  1137.     {
  1138.       register rtx tmp;
  1139.     
  1140.       /* Emit a return insn, but only if control can fall through to here.  */
  1141.  
  1142.       tmp = get_last_insn ();
  1143.       while (tmp)
  1144.     {
  1145.       if (GET_CODE (tmp) == BARRIER)
  1146.         return;
  1147.       if (GET_CODE (tmp) == CODE_LABEL)
  1148.         break;
  1149.       if (GET_CODE (tmp) == JUMP_INSN)
  1150.         {
  1151.           if (GET_CODE (PATTERN (tmp)) == RETURN)
  1152.         return;
  1153.           break;
  1154.         }
  1155.       if (GET_CODE (tmp) == NOTE)
  1156.         {
  1157.           tmp = PREV_INSN (tmp);
  1158.           continue;
  1159.         }
  1160.       break;
  1161.     }
  1162.       fprintf (file, "LR%d:    ret\n", ret_label);
  1163.       return;
  1164.     }
  1165.  
  1166.   fprintf (file, "LR%d:\n", ret_label);
  1167.  
  1168.   fprintf (file, "\t#EPILOGUE#\n");
  1169.  
  1170.   /* Output the string created by the prologue which will restore all
  1171.      registers saved by the prologue.  */
  1172.  
  1173.   if (epilogue_string[0] != '\0')
  1174.     fprintf (file, "%s", epilogue_string);
  1175.  
  1176.   /* Must clear g14 on return.  */
  1177.  
  1178.   if (current_function_args_size != 0)
  1179.     fprintf (file, "\tmov    0,g14\n");
  1180.  
  1181.   fprintf (file, "\tret\n");
  1182.   fprintf (file, "\t#End Epilogue#\n");
  1183. }
  1184.  
  1185. /* Output code for a call insn.  */
  1186.  
  1187. char *
  1188. i960_output_call_insn (target, argsize_rtx, arg_pointer, scratch_reg, insn)
  1189.      register rtx target, argsize_rtx, arg_pointer, scratch_reg, insn;
  1190. {
  1191.   int argsize = INTVAL (argsize_rtx);
  1192.   rtx nexti = next_real_insn (insn);
  1193.   rtx operands[3];
  1194.  
  1195.   operands[0] = target;
  1196.   operands[1] = arg_pointer;
  1197.   operands[2] = scratch_reg;
  1198.  
  1199.   if (current_function_args_size != 0)
  1200.     output_asm_insn ("mov    g14,%2", operands);
  1201.  
  1202.   if (argsize > 48)
  1203.     output_asm_insn ("lda    %a1,g14", operands);
  1204.   else if (current_function_args_size != 0)
  1205.     output_asm_insn ("mov    0,g14", operands);
  1206.  
  1207.   /* The code used to assume that calls to SYMBOL_REFs could not be more
  1208.      than 24 bits away (b vs bx, callj vs callx).  This is not true.  This
  1209.      feature is now implemented by relaxing in the GNU linker.  It can convert
  1210.      bx to b if in range, and callx to calls/call/balx/bal as appropriate.  */
  1211.  
  1212.   /* Nexti could be zero if the called routine is volatile.  */
  1213.   if (optimize && (*epilogue_string == 0) && argsize == 0 && tail_call_ok 
  1214.       && (nexti == 0 || GET_CODE (PATTERN (nexti)) == RETURN))
  1215.     {
  1216.       /* Delete following return insn.  */
  1217.       if (nexti && no_labels_between_p (insn, nexti))
  1218.     delete_insn (nexti);
  1219.       output_asm_insn ("bx    %0", operands);
  1220.       return "# notreached";
  1221.     }
  1222.  
  1223.   output_asm_insn ("callx    %0", operands);
  1224.  
  1225.   if (current_function_args_size != 0)
  1226.     output_asm_insn ("mov    %2,g14", operands);
  1227.  
  1228.   return "";
  1229. }
  1230.  
  1231. /* Output code for a return insn.  */
  1232.  
  1233. char *
  1234. i960_output_ret_insn (insn)
  1235.      register rtx insn;
  1236. {
  1237.   static char lbuf[20];
  1238.   
  1239.   if (*epilogue_string != 0)
  1240.     {
  1241.       if (! TARGET_CODE_ALIGN && next_real_insn (insn) == 0)
  1242.     return "";
  1243.  
  1244.       sprintf (lbuf, "b    LR%d", ret_label);
  1245.       return lbuf;
  1246.     }
  1247.  
  1248.   if (current_function_args_size != 0)
  1249.     output_asm_insn ("mov    0,g14", 0);
  1250.  
  1251.   if (i960_leaf_ret_reg >= 0)
  1252.     {
  1253.       sprintf (lbuf, "bx    (%s)", reg_names[i960_leaf_ret_reg]);
  1254.       return lbuf;
  1255.     }
  1256.   return "ret";
  1257. }
  1258.  
  1259. #if 0
  1260. /* Return a character string representing the branch prediction
  1261.    opcode to be tacked on an instruction.  This must at least
  1262.    return a null string.  */
  1263.  
  1264. char *
  1265. i960_br_predict_opcode (lab_ref, insn)
  1266.      rtx lab_ref, insn;
  1267. {
  1268.   if (TARGET_BRANCH_PREDICT)
  1269.     {
  1270.       unsigned long label_uid;
  1271.       
  1272.       if (GET_CODE (lab_ref) == CODE_LABEL)
  1273.     label_uid = INSN_UID (lab_ref);
  1274.       else if (GET_CODE (lab_ref) == LABEL_REF)
  1275.     label_uid = INSN_UID (XEXP (lab_ref, 0));
  1276.       else
  1277.     return ".f";
  1278.  
  1279.       /* If not optimizing, then the insn_addresses array will not be
  1280.      valid.  In this case, always return ".t" since most branches
  1281.      are taken.  If optimizing, return .t for backward branches
  1282.      and .f for forward branches.  */
  1283.       if (! optimize
  1284.       || insn_addresses[label_uid] < insn_addresses[INSN_UID (insn)])
  1285.     return ".t";
  1286.       return ".f";
  1287.     }
  1288.     
  1289.   return "";
  1290. }
  1291. #endif
  1292.  
  1293. /* Print the operand represented by rtx X formatted by code CODE.  */
  1294.  
  1295. void
  1296. i960_print_operand (file, x, code)
  1297.      FILE *file;
  1298.      rtx x;
  1299.      char code;
  1300. {
  1301.   enum rtx_code rtxcode = GET_CODE (x);
  1302.  
  1303.   if (rtxcode == REG)
  1304.     {
  1305.       switch (code)
  1306.     {
  1307.     case 'D':
  1308.       /* Second reg of a double.  */
  1309.       fprintf (file, "%s", reg_names[REGNO (x)+1]);
  1310.       break;
  1311.  
  1312.     case 0:
  1313.       fprintf (file, "%s", reg_names[REGNO (x)]);
  1314.       break;
  1315.  
  1316.     default:
  1317.       abort ();
  1318.     }
  1319.       return;
  1320.     }
  1321.   else if (rtxcode == MEM)
  1322.     {
  1323.       output_address (XEXP (x, 0));
  1324.       return;
  1325.     }
  1326.   else if (rtxcode == CONST_INT)
  1327.     {
  1328.       if (INTVAL (x) > 9999 || INTVAL (x) < -999)
  1329.     fprintf (file, "0x%x", INTVAL (x));
  1330.       else
  1331.     fprintf (file, "%d", INTVAL (x));
  1332.       return;
  1333.     }
  1334.   else if (rtxcode == CONST_DOUBLE)
  1335.     {
  1336.       double d;
  1337.  
  1338.       if (x == CONST0_RTX (DFmode) || x == CONST0_RTX (SFmode))
  1339.     {
  1340.       fprintf (file, "0f0.0");
  1341.       return;
  1342.     }
  1343.       else if (x == CONST1_RTX (DFmode) || x == CONST1_RTX (SFmode))
  1344.     {
  1345.       fprintf (file, "0f1.0");
  1346.       return;
  1347.     }
  1348.  
  1349.       /* This better be a comment.  */
  1350.       REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  1351.       fprintf (file, "%#g", d);
  1352.       return;
  1353.     }
  1354.  
  1355.   switch(code)
  1356.     {
  1357.     case 'B':
  1358.       /* Branch or jump, depending on assembler.  */
  1359.       if (TARGET_ASM_COMPAT)
  1360.     fputs ("j", file);
  1361.       else
  1362.     fputs ("b", file);
  1363.       break;
  1364.  
  1365.     case 'S':
  1366.       /* Sign of condition.  */
  1367.       if ((rtxcode == EQ) || (rtxcode == NE) || (rtxcode == GTU)
  1368.       || (rtxcode == LTU) || (rtxcode == GEU) || (rtxcode == LEU))
  1369.     fputs ("o", file);
  1370.       else if ((rtxcode == GT) || (rtxcode == LT)
  1371.       || (rtxcode == GE) || (rtxcode == LE))
  1372.     fputs ("i", file);
  1373.       else
  1374.     abort();
  1375.       break;
  1376.  
  1377.     case 'I':
  1378.       /* Inverted condition.  */
  1379.       rtxcode = reverse_condition (rtxcode);
  1380.       goto normal;
  1381.  
  1382.     case 'X':
  1383.       /* Inverted condition w/ reversed operands.  */
  1384.       rtxcode = reverse_condition (rtxcode);
  1385.       /* Fallthrough.  */
  1386.  
  1387.     case 'R':
  1388.       /* Reversed operand condition.  */
  1389.       rtxcode = swap_condition (rtxcode);
  1390.       /* Fallthrough.  */
  1391.  
  1392.     case 'C':
  1393.       /* Normal condition.  */
  1394.     normal:
  1395.       if (rtxcode == EQ)  { fputs ("e", file); return; }
  1396.       else if (rtxcode == NE)  { fputs ("ne", file); return; }
  1397.       else if (rtxcode == GT)  { fputs ("g", file); return; }
  1398.       else if (rtxcode == GTU) { fputs ("g", file); return; }
  1399.       else if (rtxcode == LT)  { fputs ("l", file); return; }
  1400.       else if (rtxcode == LTU) { fputs ("l", file); return; }
  1401.       else if (rtxcode == GE)  { fputs ("ge", file); return; }
  1402.       else if (rtxcode == GEU) { fputs ("ge", file); return; }
  1403.       else if (rtxcode == LE)  { fputs ("le", file); return; }
  1404.       else if (rtxcode == LEU) { fputs ("le", file); return; }
  1405.       else abort ();
  1406.       break;
  1407.  
  1408.     case 0:
  1409.       output_addr_const (file, x);
  1410.       break;
  1411.  
  1412.     default:
  1413.       abort ();
  1414.     }
  1415.  
  1416.   return;
  1417. }
  1418.  
  1419. /* Print a memory address as an operand to reference that memory location.
  1420.  
  1421.    This is exactly the same as legitimate_address_p, except that it the prints
  1422.    addresses instead of recognizing them.  */
  1423.  
  1424. void
  1425. i960_print_operand_addr (file, addr)
  1426.      FILE *file;
  1427.      register rtx addr;
  1428. {
  1429.   rtx breg, ireg;
  1430.   rtx scale, offset;
  1431.  
  1432.   ireg = 0;
  1433.   breg = 0;
  1434.   offset = 0;
  1435.   scale = const1_rtx;
  1436.  
  1437.   if (GET_CODE (addr) == REG)
  1438.     breg = addr;
  1439.   else if (CONSTANT_P (addr))
  1440.     offset = addr;
  1441.   else if (GET_CODE (addr) == PLUS)
  1442.     {
  1443.       rtx op0, op1;
  1444.  
  1445.       op0 = XEXP (addr, 0);
  1446.       op1 = XEXP (addr, 1);
  1447.  
  1448.       if (GET_CODE (op0) == REG)
  1449.     {
  1450.       breg = op0;
  1451.       if (GET_CODE (op1) == REG)
  1452.         ireg = op1;
  1453.       else if (CONSTANT_P (op1))
  1454.         offset = op1;
  1455.       else
  1456.         abort ();
  1457.     }
  1458.       else if (GET_CODE (op0) == PLUS)
  1459.     {
  1460.       if (GET_CODE (XEXP (op0, 0)) == MULT)
  1461.         {
  1462.           ireg = XEXP (XEXP (op0, 0), 0);
  1463.           scale = XEXP (XEXP (op0, 0), 1);
  1464.           if (GET_CODE (XEXP (op0, 1)) == REG)
  1465.         {
  1466.           breg = XEXP (op0, 1);
  1467.           offset = op1;
  1468.         }
  1469.           else
  1470.         abort ();
  1471.         }
  1472.       else if (GET_CODE (XEXP (op0, 0)) == REG)
  1473.         {
  1474.           breg = XEXP (op0, 0);
  1475.           if (GET_CODE (XEXP (op0, 1)) == REG)
  1476.         {
  1477.           ireg = XEXP (op0, 1);
  1478.           offset = op1;
  1479.         }
  1480.           else
  1481.         abort ();
  1482.         }
  1483.       else
  1484.         abort ();
  1485.     }
  1486.       else if (GET_CODE (op0) == MULT)
  1487.     {
  1488.       ireg = XEXP (op0, 0);
  1489.       scale = XEXP (op0, 1);
  1490.       if (GET_CODE (op1) == REG)
  1491.         breg = op1;
  1492.       else if (CONSTANT_P (op1))
  1493.         offset = op1;
  1494.       else
  1495.         abort ();
  1496.     }
  1497.       else
  1498.     abort ();
  1499.     }
  1500.   else if (GET_CODE (addr) == MULT)
  1501.     {
  1502.       breg = XEXP (addr, 0);
  1503.       scale = XEXP (addr, 1);
  1504.     }
  1505.   else
  1506.     abort ();
  1507.  
  1508.   if (offset)
  1509.     output_addr_const (file, offset);
  1510.   if (breg)
  1511.     fprintf (file, "(%s)", reg_names[REGNO (breg)]);
  1512.   if (ireg)
  1513.     fprintf (file, "[%s*%d]", reg_names[REGNO (ireg)], INTVAL (scale));
  1514. }
  1515.  
  1516. /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression
  1517.    that is a valid memory address for an instruction.
  1518.    The MODE argument is the machine mode for the MEM expression
  1519.    that wants to use this address.
  1520.  
  1521.     On 80960, legitimate addresses are:
  1522.         base                ld    (g0),r0
  1523.         disp    (12 or 32 bit)        ld    foo,r0
  1524.         base + index            ld    (g0)[g1*1],r0
  1525.         base + displ            ld    0xf00(g0),r0
  1526.         base + index*scale + displ    ld    0xf00(g0)[g1*4],r0
  1527.         index*scale + base        ld    (g0)[g1*4],r0
  1528.         index*scale + displ        ld    0xf00[g1*4],r0
  1529.         index*scale            ld    [g1*4],r0
  1530.         index + base + displ        ld    0xf00(g0)[g1*1],r0
  1531.  
  1532.     In each case, scale can be 1, 2, 4, 8, or 16.  */
  1533.  
  1534. /* This is exactly the same as i960_print_operand_addr, except that
  1535.    it recognizes addresses instead of printing them.
  1536.  
  1537.    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
  1538.    convert common non-canonical forms to canonical form so that they will
  1539.    be recognized.  */
  1540.  
  1541. int
  1542. legitimate_address_p (mode, addr, strict)
  1543.      enum machine_mode mode;
  1544.      register rtx addr;
  1545.      int strict;
  1546. {
  1547.   if (GET_CODE (addr) == REG)
  1548.     return (strict ? REG_OK_FOR_BASE_P_STRICT (addr)
  1549.         : REG_OK_FOR_BASE_P (addr));
  1550.   else if (CONSTANT_P (addr))
  1551.     return 1;
  1552.   else if (GET_CODE (addr) == PLUS)
  1553.     {
  1554.       rtx op0, op1;
  1555.  
  1556.       if (! TARGET_COMPLEX_ADDR && ! reload_completed)
  1557.     return 0;
  1558.  
  1559.       op0 = XEXP (addr, 0);
  1560.       op1 = XEXP (addr, 1);
  1561.  
  1562.       if (GET_CODE (op0) == REG)
  1563.     {
  1564.       if (! (strict ? REG_OK_FOR_BASE_P_STRICT (op0)
  1565.          : REG_OK_FOR_BASE_P (op0)))
  1566.         return 0;
  1567.  
  1568.       if (GET_CODE (op1) == REG)
  1569.         return (strict ? REG_OK_FOR_INDEX_P_STRICT (op1)
  1570.             : REG_OK_FOR_INDEX_P (op1));
  1571.       else if (CONSTANT_P (op1))
  1572.         return 1;
  1573.       else
  1574.         return 0;
  1575.     }
  1576.       else if (GET_CODE (op0) == PLUS)
  1577.     {
  1578.       if (GET_CODE (XEXP (op0, 0)) == MULT)
  1579.         {
  1580.           if (! (GET_CODE (XEXP (XEXP (op0, 0), 0)) == REG
  1581.              && (strict ? REG_OK_FOR_INDEX_P_STRICT (XEXP (XEXP (op0, 0), 0))
  1582.              : REG_OK_FOR_INDEX_P (XEXP (XEXP (op0, 0), 0)))
  1583.              && SCALE_TERM_P (XEXP (XEXP (op0, 0), 1))))
  1584.         return 0;
  1585.  
  1586.           if (GET_CODE (XEXP (op0, 1)) == REG)
  1587.         return ((strict ? REG_OK_FOR_BASE_P_STRICT (XEXP (op0, 1))
  1588.              : REG_OK_FOR_BASE_P (XEXP (op0, 1)))
  1589.             && CONSTANT_P (op1));
  1590.           else
  1591.         return 0;
  1592.         }
  1593.       else if (GET_CODE (XEXP (op0, 0)) == REG)
  1594.         {
  1595.           if (! (strict ? REG_OK_FOR_BASE_P_STRICT (XEXP (op0, 0))
  1596.              : REG_OK_FOR_BASE_P (XEXP (op0, 0))))
  1597.         return 0;
  1598.  
  1599.           if (GET_CODE (XEXP (op0, 1)) == REG)
  1600.         return ((strict ? REG_OK_FOR_INDEX_P_STRICT (XEXP (op0, 1))
  1601.              : REG_OK_FOR_INDEX_P (XEXP (op0, 1)))
  1602.             && CONSTANT_P (op1));
  1603.           else
  1604.         return 0;
  1605.         }
  1606.       else
  1607.         return 0;
  1608.     }
  1609.       else if (GET_CODE (op0) == MULT)
  1610.     {
  1611.       if (! (GET_CODE (XEXP (op0, 0)) == REG
  1612.          && (strict ? REG_OK_FOR_INDEX_P_STRICT (XEXP (op0, 0))
  1613.              : REG_OK_FOR_INDEX_P (XEXP (op0, 0)))
  1614.          && SCALE_TERM_P (XEXP (op0, 1))))
  1615.         return 0;
  1616.  
  1617.       if (GET_CODE (op1) == REG)
  1618.         return (strict ? REG_OK_FOR_BASE_P_STRICT (op1)
  1619.             : REG_OK_FOR_BASE_P (op1));
  1620.       else if (CONSTANT_P (op1))
  1621.         return 1;
  1622.       else
  1623.         return 0;
  1624.     }
  1625.       else
  1626.     return 0;
  1627.     }
  1628.   else if (GET_CODE (addr) == MULT)
  1629.     {
  1630.       if (! TARGET_COMPLEX_ADDR && ! reload_completed)
  1631.     return 0;
  1632.  
  1633.       return (GET_CODE (XEXP (addr, 0)) == REG
  1634.           && (strict ? REG_OK_FOR_INDEX_P_STRICT (XEXP (addr, 0))
  1635.           : REG_OK_FOR_INDEX_P (XEXP (addr, 0)))
  1636.           && SCALE_TERM_P (XEXP (addr, 1)));
  1637.     }
  1638.   else
  1639.     return 0;
  1640. }
  1641.  
  1642. /* Try machine-dependent ways of modifying an illegitimate address
  1643.    to be legitimate.  If we find one, return the new, valid address.
  1644.    This macro is used in only one place: `memory_address' in explow.c.
  1645.  
  1646.    This converts some non-canonical addresses to canonical form so they
  1647.    can be recognized.  */
  1648.  
  1649. rtx
  1650. legitimize_address (x, oldx, mode)
  1651.      register rtx x;
  1652.      register rtx oldx;
  1653.      enum machine_mode mode;
  1654.   if (GET_CODE (x) == SYMBOL_REF)
  1655.     {
  1656.       abort ();
  1657.       x = copy_to_reg (x);
  1658.     }
  1659.  
  1660.   if (! TARGET_COMPLEX_ADDR && ! reload_completed)
  1661.     return x;
  1662.  
  1663.   /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
  1664.      into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
  1665.      created by virtual register instantiation, register elimination, and
  1666.      similar optimizations.  */
  1667.   if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == MULT
  1668.       && GET_CODE (XEXP (x, 1)) == PLUS)
  1669.     x = gen_rtx (PLUS, Pmode,
  1670.          gen_rtx (PLUS, Pmode, XEXP (x, 0), XEXP (XEXP (x, 1), 0)),
  1671.          XEXP (XEXP (x, 1), 1));
  1672.  
  1673.   /* Canonicalize (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
  1674.      into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
  1675.   else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
  1676.        && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
  1677.        && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
  1678.        && CONSTANT_P (XEXP (x, 1)))
  1679.     {
  1680.       rtx constant, other;
  1681.  
  1682.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  1683.     {
  1684.       constant = XEXP (x, 1);
  1685.       other = XEXP (XEXP (XEXP (x, 0), 1), 1);
  1686.     }
  1687.       else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT)
  1688.     {
  1689.       constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
  1690.       other = XEXP (x, 1);
  1691.     }
  1692.       else
  1693.     constant = 0;
  1694.  
  1695.       if (constant)
  1696.     x = gen_rtx (PLUS, Pmode,
  1697.              gen_rtx (PLUS, Pmode, XEXP (XEXP (x, 0), 0),
  1698.                   XEXP (XEXP (XEXP (x, 0), 1), 0)),
  1699.              plus_constant (other, INTVAL (constant)));
  1700.     }
  1701.  
  1702.   return x;
  1703. }
  1704.  
  1705. #if 0
  1706. /* Return the most stringent alignment that we are willing to consider
  1707.    objects of size SIZE and known alignment ALIGN as having. */
  1708.    
  1709. int
  1710. i960_alignment (size, align)
  1711.      int size;
  1712.      int align;
  1713. {
  1714.   int i;
  1715.  
  1716.   if (! TARGET_STRICT_ALIGN)
  1717.     if (TARGET_IC_COMPAT2_0 || align >= 4)
  1718.       {
  1719.     i = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
  1720.     if (i > align)
  1721.       align = i;
  1722.       }
  1723.  
  1724.   return align;
  1725. }
  1726. #endif
  1727.  
  1728. /* Modes for condition codes.  */
  1729. #define C_MODES        \
  1730.   ((1 << (int) CCmode) | (1 << (int) CC_UNSmode) | (1<< (int) CC_CHKmode))
  1731.  
  1732. /* Modes for single-word (and smaller) quantities.  */
  1733. #define S_MODES                        \
  1734.  (~C_MODES                        \
  1735.   & ~ ((1 << (int) DImode) | (1 << (int) TImode)    \
  1736.        | (1 << (int) DFmode) | (1 << (int) TFmode)))
  1737.  
  1738. /* Modes for double-word (and smaller) quantities.  */
  1739. #define D_MODES                    \
  1740.   (~C_MODES                    \
  1741.    & ~ ((1 << (int) TImode) | (1 << (int) TFmode)))
  1742.  
  1743. /* Modes for quad-word quantities.  */
  1744. #define T_MODES (~C_MODES)
  1745.  
  1746. /* Modes for single-float quantities.  */
  1747. #define SF_MODES ((1 << (int) SFmode))
  1748.  
  1749. /* Modes for double-float quantities.  */
  1750. #define DF_MODES (SF_MODES | (1 << (int) DFmode) | (1 << (int) SCmode))
  1751.  
  1752. /* Modes for quad-float quantities.  */
  1753. #define TF_MODES (DF_MODES | (1 << (int) TFmode) | (1 << (int) DCmode))
  1754.  
  1755. unsigned int hard_regno_mode_ok[FIRST_PSEUDO_REGISTER] = {
  1756.   T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
  1757.   T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
  1758.   T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
  1759.   T_MODES, S_MODES, D_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES,
  1760.  
  1761.   TF_MODES, TF_MODES, TF_MODES, TF_MODES, C_MODES};
  1762.  
  1763.  
  1764. /* Return the minimum alignment of an expression rtx X in bytes.  This takes
  1765.    advantage of machine specific facts, such as knowing that the frame pointer
  1766.    is always 16 byte aligned.  */
  1767.  
  1768. int
  1769. i960_expr_alignment (x, size)
  1770.      rtx x;
  1771.      int size;
  1772. {
  1773.   int align = 1;
  1774.  
  1775.   if (x == 0)
  1776.     return 1;
  1777.  
  1778.   switch (GET_CODE(x))
  1779.     {
  1780.     case CONST_INT:
  1781.       align = INTVAL(x);
  1782.  
  1783.       if ((align & 0xf) == 0)
  1784.     align = 16;
  1785.       else if ((align & 0x7) == 0)
  1786.     align = 8;
  1787.       else if ((align & 0x3) == 0)
  1788.     align = 4;
  1789.       else if ((align & 0x1) == 0)
  1790.     align = 2;
  1791.       else
  1792.     align = 1;
  1793.       break;
  1794.  
  1795.     case PLUS:
  1796.       align = MIN (i960_expr_alignment (XEXP (x, 0), size),
  1797.            i960_expr_alignment (XEXP (x, 1), size));
  1798.       break;
  1799.  
  1800.     case SYMBOL_REF:
  1801.       /* If this is a valid program, objects are guaranteed to be
  1802.      correctly aligned for whatever size the reference actually is. */
  1803.       align = i960_object_bytes_bitalign (size) / BITS_PER_UNIT;
  1804.       break;
  1805.  
  1806.     case REG:
  1807.       if (REGNO (x) == FRAME_POINTER_REGNUM)
  1808.     align = 16;
  1809.       break;
  1810.  
  1811.     case ASHIFT:
  1812.     case LSHIFT:
  1813.       align = i960_expr_alignment (XEXP (x, 0));
  1814.  
  1815.       if (GET_CODE (XEXP (x, 1)) == CONST_INT)
  1816.     {
  1817.       align = align << INTVAL (XEXP (x, 1));
  1818.       align = MIN (align, 16);
  1819.     }
  1820.       break;
  1821.  
  1822.     case MULT:
  1823.       align = (i960_expr_alignment (XEXP (x, 0), size) *
  1824.            i960_expr_alignment (XEXP (x, 1), size));
  1825.  
  1826.       align = MIN (align, 16);
  1827.       break;
  1828.     }
  1829.  
  1830.   return align;
  1831. }
  1832.  
  1833. /* Return true if it is possible to reference both BASE and OFFSET, which
  1834.    have alignment at least as great as 4 byte, as if they had alignment valid
  1835.    for an object of size SIZE.  */
  1836.  
  1837. int
  1838. i960_improve_align (base, offset, size)
  1839.      rtx base;
  1840.      rtx offset;
  1841.      int size;
  1842. {
  1843.   int i, j;
  1844.  
  1845.   /* We have at least a word reference to the object, so we know it has to
  1846.      be aligned at least to 4 bytes.  */
  1847.  
  1848.   i = MIN (i960_expr_alignment (base, 4),
  1849.        i960_expr_alignment (offset, 4));
  1850.  
  1851.   i = MAX (i, 4);
  1852.  
  1853.   /* We know the size of the request.  If strict align is not enabled, we
  1854.      can guess that the alignment is OK for the requested size.  */
  1855.  
  1856.   if (! TARGET_STRICT_ALIGN)
  1857.     if ((j = (i960_object_bytes_bitalign (size) / BITS_PER_UNIT)) > i)
  1858.       i = j;
  1859.  
  1860.   return (i >= size);
  1861. }
  1862.  
  1863. /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
  1864.    (SImode) alignment as if they had 16 byte (TImode) alignment.  */
  1865.  
  1866. int
  1867. i960_si_ti (base, offset)
  1868.      rtx base;
  1869.      rtx offset;
  1870. {
  1871.   return i960_improve_align (base, offset, 16);
  1872. }
  1873.  
  1874. /* Return true if it is possible to access BASE and OFFSET, which have 4 byte
  1875.    (SImode) alignment as if they had 8 byte (DImode) alignment.  */
  1876.  
  1877. int
  1878. i960_si_di (base, offset)
  1879.      rtx base;
  1880.      rtx offset;
  1881. {
  1882.   return i960_improve_align (base, offset, 8);
  1883. }
  1884.  
  1885. /* Return raw values of size and alignment (in words) for the data
  1886.    type being accessed.  These values will be rounded by the caller.  */
  1887.  
  1888. static void 
  1889. i960_arg_size_and_align (mode, type, size_out, align_out)
  1890.      enum machine_mode mode;
  1891.      tree type;
  1892.      int *size_out;
  1893.      int *align_out;
  1894. {
  1895.   int size, align;
  1896.  
  1897.   /* Use formal alignment requirements of type being passed, except make
  1898.      it at least a word.  If we don't have a type, this is a library call,
  1899.      and the parm has to be of scalar type.  In this case, consider its
  1900.      formal alignment requirement to be its size in words.  */
  1901.  
  1902.   if (mode == BLKmode)
  1903.     size = (int_size_in_bytes (type) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  1904.   else if (mode == VOIDmode)
  1905.     {
  1906.       /* End of parm list.  */
  1907.       assert (type != 0 && TYPE_MODE (type) == VOIDmode);
  1908.       size = 1;
  1909.     }
  1910.   else
  1911.     size = (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
  1912.  
  1913.   if (type == 0)
  1914.     align = size;
  1915.   else if (TYPE_ALIGN (type) >= BITS_PER_WORD)
  1916.     align = TYPE_ALIGN (type) / BITS_PER_WORD;
  1917.   else
  1918.     align = 1;
  1919.  
  1920.   *size_out  = size;
  1921.   *align_out = align;
  1922. }
  1923.  
  1924. /* On the 80960 the first 12 args are in registers and the rest are pushed.
  1925.    Any arg that is bigger than 4 words is placed on the stack and all
  1926.    subsequent arguments are placed on the stack.
  1927.  
  1928.    Additionally, parameters with an alignment requirement stronger than
  1929.    a word must be be aligned appropriately.  */
  1930.  
  1931. /* Update CUM to advance past an argument described by MODE and TYPE.  */
  1932.  
  1933. void
  1934. i960_function_arg_advance (cum, mode, type, named)
  1935.      CUMULATIVE_ARGS *cum;
  1936.      enum machine_mode mode;
  1937.      tree type;
  1938.      int named;
  1939. {
  1940.   int size, align;
  1941.  
  1942.   i960_arg_size_and_align (mode, type, &size, &align);
  1943.  
  1944.   if (named == 0 || size > 4 || cum->ca_nstackparms != 0
  1945.       || (size + ROUND (cum->ca_nregparms, align)) > NPARM_REGS
  1946.       || MUST_PASS_IN_STACK (mode, type))
  1947.     cum->ca_nstackparms = ROUND (cum->ca_nstackparms, align) + size;
  1948.   else
  1949.     cum->ca_nregparms = ROUND (cum->ca_nregparms, align) + size;
  1950. }
  1951.  
  1952. /* Return the register that the argument described by MODE and TYPE is
  1953.    passed in, or else return 0 if it is passed on the stack.  */
  1954.  
  1955. rtx
  1956. i960_function_arg (cum, mode, type, named)
  1957.      CUMULATIVE_ARGS *cum;
  1958.      enum machine_mode mode;
  1959.      tree type;
  1960.      int named;
  1961. {
  1962.   rtx ret;
  1963.   int size, align;
  1964.  
  1965.   i960_arg_size_and_align (mode, type, &size, &align);
  1966.  
  1967.   if (named == 0 || size > 4 || cum->ca_nstackparms != 0
  1968.       || (size + ROUND (cum->ca_nregparms, align)) > NPARM_REGS
  1969.       || MUST_PASS_IN_STACK (mode, type))
  1970.     {
  1971.       cum->ca_nstackparms = ROUND (cum->ca_nstackparms, align);
  1972.       ret = 0;
  1973.     }
  1974.   else
  1975.     {
  1976.       cum->ca_nregparms = ROUND (cum->ca_nregparms, align);
  1977.       ret = gen_rtx (REG, mode, cum->ca_nregparms);
  1978.     }
  1979.  
  1980.   return ret;
  1981. }
  1982.  
  1983. /* Floating-point support.  */
  1984.  
  1985. void
  1986. i960_output_double (file, value)
  1987.      FILE *file;
  1988.      double value;
  1989. {
  1990.   if (REAL_VALUE_ISINF (value))
  1991.     {
  1992.       fprintf (file, "\t.word    0\n");
  1993.       fprintf (file, "\t.word    0x7ff00000    # Infinity\n");
  1994.     }
  1995.   else
  1996.     fprintf (file, "\t.double 0d%.17e\n", (value));
  1997. }
  1998.  
  1999. void
  2000. i960_output_float (file, value)
  2001.      FILE *file;
  2002.      double value;
  2003. {
  2004.   if (REAL_VALUE_ISINF (value))
  2005.     fprintf (file, "\t.word    0x7f800000    # Infinity\n");
  2006.   else
  2007.     fprintf (file, "\t.float 0f%.12e\n", (value));
  2008. }
  2009.  
  2010. /* Return the number of bits that an object of size N bytes is aligned to.  */
  2011.  
  2012. int
  2013. i960_object_bytes_bitalign (n)
  2014.      int n;
  2015. {
  2016.   if (n > 8)      n = 128;
  2017.   else if (n > 4) n = 64;
  2018.   else if (n > 2) n = 32;
  2019.   else if (n > 1) n = 16;
  2020.   else            n = 8;
  2021.  
  2022.   return n;
  2023. }
  2024.  
  2025. /* Compute the size of an aggregate type TSIZE.  */
  2026.  
  2027. tree
  2028. i960_round_size (tsize)
  2029.      tree tsize;
  2030. {
  2031.   int size, byte_size, align;
  2032.  
  2033.   if (TREE_CODE (tsize) != INTEGER_CST)
  2034.     return tsize;
  2035.  
  2036.   size = TREE_INT_CST_LOW (tsize);
  2037.   byte_size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  2038.   align = i960_object_bytes_bitalign (byte_size);
  2039.  
  2040.   /* Handle #pragma align.  */
  2041.   if (align > i960_maxbitalignment)
  2042.     align = i960_maxbitalignment;
  2043.  
  2044.   if (size % align)
  2045.     size = ((size / align) + 1) * align;
  2046.  
  2047.   return size_int (size);
  2048. }
  2049.  
  2050. /* Compute the alignment for an aggregate type TSIZE.  */
  2051.  
  2052. int
  2053. i960_round_align (align, tsize)
  2054.      int align;
  2055.      tree tsize;
  2056. {
  2057.   int byte_size;
  2058.  
  2059.   if (TREE_CODE (tsize) != INTEGER_CST)
  2060.     return align;
  2061.  
  2062.   byte_size = (TREE_INT_CST_LOW (tsize) + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  2063.   align = i960_object_bytes_bitalign (byte_size);
  2064.   return align;
  2065. }
  2066.  
  2067. /* Do any needed setup for a varargs function.  For the i960, we must
  2068.    create a register parameter block if one doesn't exist, and then copy
  2069.    all register parameters to memory.  */
  2070.  
  2071. void
  2072. i960_setup_incoming_varargs (cum, mode, type, pretend_size, no_rtl)
  2073.      CUMULATIVE_ARGS *cum;
  2074.      enum machine_mode mode;
  2075.      tree type;
  2076.      int *pretend_size;
  2077.      int no_rtl;
  2078. {
  2079.   if (cum->ca_nregparms < NPARM_REGS)
  2080.     {
  2081.       int first_reg_offset = cum->ca_nregparms;
  2082.  
  2083.       if (first_reg_offset > NPARM_REGS)
  2084.     first_reg_offset = NPARM_REGS;
  2085.  
  2086.       if (! (no_rtl) && first_reg_offset != NPARM_REGS)
  2087.     {
  2088.       rtx label = gen_label_rtx ();
  2089.       emit_insn (gen_cmpsi (arg_pointer_rtx, const0_rtx));
  2090.       emit_jump_insn (gen_bne (label));
  2091.       emit_insn (gen_rtx (SET, VOIDmode, arg_pointer_rtx,
  2092.                   stack_pointer_rtx));
  2093.       emit_insn (gen_rtx (SET, VOIDmode, stack_pointer_rtx,
  2094.                   memory_address (SImode,
  2095.                           plus_constant (stack_pointer_rtx,
  2096.                                  48))));
  2097.       emit_label (label);
  2098.       move_block_from_reg
  2099.         (first_reg_offset,
  2100.          gen_rtx (MEM, BLKmode, virtual_incoming_args_rtx),
  2101.          NPARM_REGS - first_reg_offset);
  2102.     }
  2103.       *pretend_size = (NPARM_REGS - first_reg_offset) * UNITS_PER_WORD;
  2104.     }
  2105. }
  2106.  
  2107. /* Calculate the final size of the reg parm stack space for the current
  2108.    function, based on how many bytes would be allocated on the stack.  */
  2109.  
  2110. int
  2111. i960_final_reg_parm_stack_space (const_size, var_size)
  2112.      int const_size;
  2113.      tree var_size;
  2114. {
  2115.   if (var_size || const_size > 48)
  2116.     return 48;
  2117.   else
  2118.     return 0;
  2119. }
  2120.  
  2121. /* Calculate the size of the reg parm stack space.  This is a bit complicated
  2122.    on the i960.  */
  2123.  
  2124. int
  2125. i960_reg_parm_stack_space (fndecl)
  2126.      tree fndecl;
  2127. {
  2128.   /* In this case, we are called from emit_library_call, and we don't need
  2129.      to pretend we have more space for parameters than what's apparent.  */
  2130.   if (fndecl == 0)
  2131.     return 0;
  2132.  
  2133.   /* In this case, we are called from locate_and_pad_parms when we're
  2134.      not IN_REGS, so we have an arg block.  */
  2135.   if (fndecl != current_function_decl)
  2136.     return 48;
  2137.  
  2138.   /* Otherwise, we have an arg block if the current function has more than
  2139.      48 bytes of parameters.  */
  2140.   if (current_function_args_size != 0)
  2141.     return 48;
  2142.   else
  2143.     return 0;
  2144. }
  2145.  
  2146. /* Return the register class of a scratch register needed to copy IN into
  2147.    or out of a register in CLASS in MODE.  If it can be done directly,
  2148.    NO_REGS is returned.  */
  2149.  
  2150. enum reg_class
  2151. secondary_reload_class (class, mode, in)
  2152.      enum reg_class class;
  2153.      enum machine_mode mode;
  2154.      rtx in;
  2155. {
  2156.   int regno = -1;
  2157.  
  2158.   if (GET_CODE (in) == REG || GET_CODE (in) == SUBREG)
  2159.     regno = true_regnum (in);
  2160.  
  2161.   /* We can place anything into LOCAL_OR_GLOBAL_REGS and can put
  2162.      LOCAL_OR_GLOBAL_REGS into anything.  */
  2163.   if (class == LOCAL_OR_GLOBAL_REGS || class == LOCAL_REGS
  2164.       || class == GLOBAL_REGS || (regno >= 0 && regno < 32))
  2165.     return NO_REGS;
  2166.  
  2167.   /* We can place any hard register, 0.0, and 1.0 into FP_REGS.  */
  2168.   if (class == FP_REGS
  2169.       && ((regno >= 0 && regno <= FIRST_PSEUDO_REGISTER)
  2170.       || in == CONST0_RTX (mode) || in == CONST1_RTX (mode)))
  2171.     return NO_REGS;
  2172.  
  2173.   return LOCAL_OR_GLOBAL_REGS;
  2174. }
  2175.  
  2176. /* Look at the opcode P, and set i96_last_insn_type to indicate which
  2177.    function unit it executed on.  */
  2178.  
  2179. /* ??? This would make more sense as an attribute.  */
  2180.  
  2181. void
  2182. i960_scan_opcode (p)
  2183.      char *p;
  2184. {
  2185.   switch (*p)
  2186.     {
  2187.     case 'a':
  2188.     case 'd':
  2189.     case 'e':
  2190.     case 'm':
  2191.     case 'n':
  2192.     case 'o':
  2193.     case 'r':
  2194.       /* Ret is not actually of type REG, but it won't matter, because no
  2195.      insn will ever follow it.  */
  2196.     case 'u':
  2197.     case 'x':
  2198.       i960_last_insn_type = I_TYPE_REG;
  2199.       break;
  2200.  
  2201.     case 'b':
  2202.       if (p[1] == 'x' || p[3] == 'x')
  2203.         i960_last_insn_type = I_TYPE_MEM;
  2204.       i960_last_insn_type = I_TYPE_CTRL;
  2205.       break;
  2206.  
  2207.     case 'f':
  2208.     case 't':
  2209.       i960_last_insn_type = I_TYPE_CTRL;
  2210.       break;
  2211.  
  2212.     case 'c':
  2213.       if (p[1] == 'a')
  2214.     {
  2215.       if (p[4] == 'x')
  2216.         i960_last_insn_type = I_TYPE_MEM;
  2217.       else
  2218.         i960_last_insn_type = I_TYPE_CTRL;
  2219.     }
  2220.       else if (p[1] == 'm')
  2221.     {
  2222.       if (p[3] == 'd')
  2223.         i960_last_insn_type = I_TYPE_REG;
  2224.       else if (p[4] == 'b' || p[4] == 'j')
  2225.         i960_last_insn_type = I_TYPE_CTRL;
  2226.       else
  2227.         i960_last_insn_type = I_TYPE_REG;
  2228.     }
  2229.       else
  2230.         i960_last_insn_type = I_TYPE_REG;
  2231.       break;
  2232.  
  2233.     case 'l':
  2234.       i960_last_insn_type = I_TYPE_MEM;
  2235.       break;
  2236.  
  2237.     case 's':
  2238.       if (p[1] == 't')
  2239.         i960_last_insn_type = I_TYPE_MEM;
  2240.       else
  2241.         i960_last_insn_type = I_TYPE_REG;
  2242.       break;
  2243.     }
  2244. }
  2245.